﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TeacherManage.aspx.cs" Inherits="Educational_Teacher_TeacherManage" %>
<script type="text/javascript">
window.addEvent('domready',function(){
    var teacher={};
    teacher.addFormCheck=function(){
        new FormCheck('formAddForTeacher',{display:{tipsPosition:'left'},submit:false,onValidateSuccess:function(){
            MUI.showModalMessage('正在添加教师用户');
            new Request.JSON({url:'../Ajax/TeacherManage.aspx?Action=saveAddTeacher',noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    $('windowAddForTeacher').retrieve('instance').close();
                    MUI.appendStatusMessage({'text':result.msg});
                    teacher.datagrid.loadData();
                }
	        },onFailure:function(error){
		        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		        MUI.hideModalMessage();
            }}).post($('formAddForTeacher'));
        }});   
    };
    teacher.showAddForm=function(){
        MUI.openContentByWindow('windowAddForTeacher','添加教师',$('formContainerForTeacher'),$('formAddForTeacher'),400,180);
    };
    
    teacher.updateFormCheck=function(){
        new FormCheck('formUpdateForTeacher',{display:{tipsPosition:'left'},submit:false,onValidateSuccess:function(){
            MUI.showModalMessage('正在修改教师用户');
            new Request.JSON({url:'../Ajax/TeacherManage.aspx?Action=saveUpdateTeacher',noCache:true,onSuccess:function(result){
                MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    $('windowUpdateForTeacher').retrieve('instance').close();
                    MUI.appendStatusMessage({'text':result.msg});
                    teacher.datagrid.loadData();
                }
	        },onFailure:function(error){
		        MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
		        MUI.hideModalMessage();
            }}).post($('formUpdateForTeacher'));
        }});   
    };
    teacher.showUpdateForm=function(){
        var indices = teacher.datagrid.getSelectedIndices();
        if (indices.length == 0)
	    {
		    MUI.showModalAlert('您必须至少选定一行');
		    return;
	    }
	    if (indices.length > 1)
	    {
		    MUI.showModalAlert('修改时不允许一次修改多行数据。。');
		    return;
	    }
	    var selectedData=teacher.datagrid.getDataByRow(indices[0]);
	    var element=$('formUpdateForTeacher');
	    element.getElement('.teacherId').set('value',selectedData.teacherId);
	    element.getElement('.teacherName').set('text',selectedData.teacherName);
	    element.getElement('.loginPass').set('value','');
	    element.getElement('.confirmLoginPass').set('value','');
	    Util.setSelectedValue('jobTitle2',selectedData.jobTitle.dictionaryId);
	    Util.setSelectedValue('status',selectedData.status);
        MUI.openContentByWindow('windowUpdateForTeacher','修改教师',$('formContainerForTeacher'),$('formUpdateForTeacher'),400,180);
    };
    
    teacher.deleteForTeacher=function(){
        var indices = teacher.datagrid.getSelectedIndices();
        if (indices.length == 0)
	    {
		    MUI.showModalAlert('您必须至少选定一行');
		    return;
	    }
	    MUI.showConfirm('您确定要删除所选定的数据？此操作不可恢复！',function(){
	        var teacherIds='';
	        for (var i=0; i<indices.length; i++)
	        {
		        teacherIds+=teacher.datagrid.getDataByRow(indices[i]).teacherId+',';
	        }
	        MUI.showModalMessage('正在删除所选中的教师');
	        new Request.JSON({url:'../Ajax/TeacherManage.aspx?Action=deleteTeacher&teacherIds='+teacherIds,noCache:true,onSuccess:function(result){
	            MUI.hideModalMessage();
                if(result.error)
                    MUI.appendStatusMessage({'text':result.msg});
                else
                {
                    MUI.appendStatusMessage({'text':result.msg});
                    teacher.datagrid.loadData();
                }
            },onFailure:function(error){
	            MUI.appendStatusMessage({'text':'AJAX提交表单的过程中发生未知错误。'});
	            MUI.hideModalMessage();
            }}).get();
        });
    };
    
    teacher.loadData=function(){
        teacher.datagrid = new omniGrid('dataListForTeacher', {
            columnModel: [
                {header: '教师姓名',dataIndex: 'teacherName',dataType:'string',width:80,sortable:true},
                {header: '性别',dataIndex: 'teacherSex',dataType:'string',width:50,sortable:true},
                {header: '职称',dataIndex: 'teacherId',dataType:'number',width:100,sortable:true,labelFunction:function(rowdata, r, columnModel){
                    return rowdata.jobTitle.dictionaryValue;
                }},
                {header: '登录Id',dataIndex: 'loginId',dataType:'string',width:100,sortable:true},
                {header: '最后登录时间',dataIndex: 'lastLoginTime',dataType:'string',width:150,sortable:true},
                {header: '最后登录IP',dataIndex: 'lastLoginIp',dataType:'string',width:130,sortable:true},
                {header: '登录次数',dataIndex: 'loginTimes',dataType:'number',width:80,sortable:true},
                {header: '注册时间',dataIndex: 'regTime',dataType:'string',width:150,sortable:true},
                {header: '状态',dataIndex: 'teacherId',dataType:'number',width:70,labelFunction:function(rowdata, r, columnModel){
                    if(rowdata.status==1)
                        return '<span style="color:#0000FF">离职</span>';
                    if(rowdata.status==2)
                        return '<span style="color:#FF0000">锁定</span>';
                    if(rowdata.status==0)
                        return '<span style="color:#0000FF">退休</span>';
                    if(rowdata.status==9)
                        return '正常';
                }}
            ],
            buttons : [
                {name: '添加', bclass: 'add', onclick : teacher.showAddForm},
                {name: '修改', bclass: 'update', onclick : teacher.showUpdateForm},
                {name: '删除', bclass: 'delete', onclick : teacher.deleteForTeacher}
            ],
            url:'../Ajax/TeacherManage.aspx?Action=search',
            urlMethod:'post',
            urlPostForm:'searchFormForTeacher',
            perPageOptions: [20,50,100,200,500,1000],
            perPage:20,
            height:$('dataListForTeacher').getParent().getParent().getStyle('height').toInt(),
            serverSort:false,
            sortHeader:true,
            pagination:true
        });
    };

    teacher.binddingEvent=function(){
        $('searchFormForTeacher').getElement('.button').addEvent('click',function(){
            teacher.datagrid.options.page=1;
            teacher.datagrid.loadData();
        });
    };
    
    teacher.initialize=function(){
        new ZebraTable({elements:'table.tableFixed'});
        teacher.loadData();
        teacher.binddingEvent();
        teacher.addFormCheck();
        teacher.updateFormCheck();
    };
    
    teacher.init=function(){
        teacher.initialize();
    };
    
    teacher.init();
});
</script>
<div id="dataListForTeacher"></div>
<!--隐藏的表单-->
<div id="formContainerForTeacher" style="display:none;">
<!--搜索条件表单-->
<form id="searchFormForTeacher">
    <span class="span">教师姓名</span>
    <input class="input" style="width:70px;" type="text" name="teacherName" />
    <span class="span">登录ID</span>
    <input class="input" style="width:70px;" type="text" name="loginId" />
    <input class="button" type="button" value="查询" />
</form>
<!--添加教师表单-->
<form id="formAddForTeacher">
<table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">教师姓名：</td>
        <td class="tableLeft2"><input class="input validate['required','length[2,4]']" name="teacherName" type="text" /></td>
    </tr>
    <tr>
        <td class="tableLeft1">登录ID：</td>
        <td class="tableLeft2"><input class="input validate['required','alphanum','length[4,16]']" name="loginId" type="text" /></td>
    </tr>
    <tr>
        <td class="tableLeft1">登录密码：</td>
        <td class="tableLeft2"><input class="input validate['required','length[6,16]']" name="loginPass" type="password" /></td>
    </tr>
    <tr>
        <td class="tableLeft1">确认密码：</td>
        <td class="tableLeft2"><input class="input validate['required','length[6,16]']" name="confirmLoginPass" type="password" /></td>
    </tr>
    <tr>
        <td class="tableLeft1">请选择职称：</td>
        <td class="tableLeft2"><%=selectStr%></td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交添加" /></td>
    </tr>
</table>
</form>
<!--修改教师表单-->
<form id="formUpdateForTeacher">
<input class="teacherId" type="hidden" name="teacherId" value="" />
    <table class="tableFixed" border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
        <td class="tableLeft1">教师姓名：</td>
        <td class="tableLeft2"><span class="teacherName"></span></td>
    </tr>
    <tr>
        <td class="tableLeft1">登录密码：</td>
        <td class="tableLeft2"><input class="input loginPass" name="loginPass" type="password" />不修改请留空</td>
    </tr>
    <tr>
        <td class="tableLeft1">确认密码：</td>
        <td class="tableLeft2"><input class="input confirmLoginPass" name="confirmLoginPass" type="password" /></td>
    </tr>
    <tr>
        <td class="tableLeft1">请选择职称：</td>
        <td class="tableLeft2"><%=selectStr2%></td>
    </tr>
    <tr>
        <td class="tableLeft1">请选择状态：</td>
        <td class="tableLeft2">
            <select id="status" class="input" name="status">
                <option value="9">正常</option>
                <option value="0">退休</option>
                <option value="1">已离职</option>
                <option value="2">锁定</option>
            </select>
        </td>
    </tr>
    <tr>
        <td class="tableLeft1"></td>
        <td class="tableLeft2"><input class="submit button validate['submit']" type="button" value="提交修改" /></td>
    </tr>
</table>
</form>
</div>